<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="分类:" prop="category.value">
                            <SelectPage v-model="queryParams.category.value" :url="'/admin/productcate/selectPage'" show_field="title" query_field="title" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="编号:" prop="brand.value">
                            <el-input v-model="queryParams.brand.value" placeholder="请输入编号" clearable />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="运营:" prop="operation.value">
                            <el-input v-model="queryParams.operation.value" placeholder="请输入运营" clearable />
                        </el-form-item>
                    </el-col> -->

                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <!-- <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col> -->
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>
            
            <el-tabs v-model="activeTab" @tab-click="handleStatus" type="border-card">
                <el-tab-pane v-for="(item, index) in status" :key="index" :label="item.label" :name="item.value.toString()">
            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="240" align="left">
                        <template slot-scope="scope">
                            <el-button class="btn-mar" size="mini" type="success" @click="handleSkuaddEdit(scope.row)" v-hasPermi="api.skumanageadd">sku添加</el-button>
                            <el-button class="btn-mar" size="mini" type="primary" @click="handleSkuEdit(scope.row)" v-hasPermi="api.skumanage">sku管理</el-button>
                            <el-button class="btn-mar" size="mini" type="primary" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button>
                            <!-- <el-button class="btn-mar" size="mini" type="info" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button> -->
                            <!-- <el-button class="btn-mar" size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button> -->

                        </template>
                    </el-table-column>
                </template>
            </qa-table>
               </el-tab-pane>
            </el-tabs>
            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
        <el-dialog :title="!disabled ? 'sku添加' : '详情'" :visible="skuaddOpen" :before-close="beforeSkuaddClose" destroy-on-close>
            <EditSkuaddForm ref="editSkuaddForm" :findFormData="findFormData" :disabled="disabled" @submitSkuaddForm="submitSkuaddForm2" :editFormParams="editFormParams" @editSkuaddFormCancel="beforeSkuaddClose" />
        </el-dialog>
        <el-dialog :title="!disabled ? 'sku修改' : '详情'" :visible="skuOpen" :before-close="beforeSkuClose" destroy-on-close>
            <EditSkuForm ref="editSkuForm" :findFormData="findFormData" :disabled="disabled" @submitSkuForm="submitSkuForm2" :editFormParams="editFormParams" @editSkuFormCancel="beforeSkuClose" />
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
import EditSkuForm from './EditSkuFormCom'
import EditSkuaddForm from './EditSkuaddFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm,EditSkuForm,EditSkuaddForm },
    
    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: '类目',
                    prop: 'category',
                },
                {
                    visible: true,
                    label: '编号',
                    prop: 'brand',
                },

                // {
                //     visible: true,
                //     label: '产品库类型',
                //     prop: 'product_type',
                // },

                {
                    visible: true,
                    label: '产品库类型',
                    prop: 'product_type',
                    width: 180,
                    component: 'QuickAdminTag',
                    formatter: (prop, row) => {
                        return row.flag_text
                    },
                },

                {
                    visible: true,
                    label: '中文名称',
                    prop: 'chinese_name',
                },

                {
                    visible: true,
                    label: '运输方式',
                    prop: 'transport',
                },

                {
                    visible: true,
                    label: '体积',
                    prop: 'volume',
                },

                {
                    visible: true,
                    label: '投放开发人员',
                    prop: 'dev_admin',
                },
                // {
                //     visible: true,
                //     label: '在投人数',
                //     prop: 'put_num',
                // },
                {
                    visible: true,
                    label: '上架时间',
                    prop: 'xp_time',
                },
                {
                    visible: true,
                    label: '爆品时间',
                    prop: 'bp_time',
                },
                
                {
                    visible: true,
                    label: '图片组',
                    prop: 'images',
                    component:'QuickAdminImage',
                },
            
                {
                    visible: true,
                    label: '尺码',
                    prop: 'size',
                },
                {
                    visible: true,
                    label: '颜色',
                    prop: 'color',
                },
                {
                    visible: true,
                    label: '采购成本(元)',
                    prop: 'purchase_price',
                },
                {
                    visible: true,
                    label: '采购类型',
                    prop: 'purchase_type',
                },
                {
                    visible: true,
                    label: '采购货源链接',
                    prop: 'link',
                },

                {
                    visible: true,
                    label: '重量',
                    prop: 'weight',
                },

                {
                    visible: true,
                    label: '预估单件物流费',
                    prop: 'per_wlprice',
                },
                {
                    visible: true,
                    label: '最低建议价',
                    prop: 'low_recomand',
                },
                {
                    visible: true,
                    label: '最高建议价',
                    prop: 'height_recomand',
                },
                {
                    visible: true,
                    label: '销售毛利额',
                    prop: 'sale_gross',
                },
                {
                    visible: true,
                    label: '销售毛利率',
                    prop: 'sale_gross_rate',
                },
                {
                    visible: true,
                    label: '开发类型',
                    prop: 'devlop',
                }, 
                // {
                //     visible: true,
                //     label: '状态',
                //     prop: 'status',
                //     component: 'QuickAdminSwitch',
                // },

            ],
            // 接口地址
            api: {
                index: `/admin/product.info/index`,
                find: `/admin/product.info/find`,
                add: `/admin/product.info/add`,
                edit: `/admin/product.info/edit`,
                delete: `/admin/product.info/delete`,
                export: `/admin/product.info/export`,
                skumanage: `/admin/product.info/skumanage`,
                skumanageadd: `/admin/product.info/skumanageadd`,
                status: `/admin/product.info/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            skuOpen: false,
            skuaddOpen: false,
            // 查询参数
            queryParams: {
                category: { value:undefined, op: '='},
                brand: { value:undefined, op: '%like%'},
                operation: { value:undefined, op: '%like%'},
                product_type: { value:undefined, op: '='},

            },

            status: [
                { label: '全部', value: '' },
                { label: '独立站', value: 1 },
                { label: 'tiktok', value: 2 },
              ],
             activeTab: '',

        }
    },
    created () {
        this.initIndex()
    },
    watch: {
        
    },
    methods: {
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },

        handleStatus(tab) {
            this.queryParams.product_type.value = tab.name
            this.submitSearch()
        },
        
        // sku生成
        handleSkuEdit(row) {
            this.handleSkuFind(row[this.primaryKey])
        },
        // sku生成回显
        async handleSkuFind(id) {
            let response = await this.request.get(this.api.skumanage, { params: { id: id } })
            this.findFormData = this.formatFindData(response.data)
            this.skuOpen = true
        },
        // sku生成
        handleSkuaddEdit(row) {
            this.handleSkuaddFind(row[this.primaryKey])
        },
        // sku生成回显
        async handleSkuaddFind(id) {
            let response = await this.request.get(this.api.skumanageadd, { params: { id: id } })
            this.findFormData = this.formatFindData(response.data)
            this.skuaddOpen = true
        },
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
